package com.itheima_01.studentsystem;

import java.util.ArrayList;

public class indexTest {
    public static void main(String[] args) {
        ArrayList<Student> list=new ArrayList<>();
        Student stu1=new Student("1","a",3,"971117");
        Student stu2=new Student("2","a",3,"971117");
        Student stu3=new Student("3","a",3,"971117");
        Student stu4=new Student("4","a",3,"971117");
        list.add(stu1);
        list.add(stu2);
        list.add(stu3);
        list.add(stu4);

        int index1=getIndex(list,"2");
        int index2=getIndex(list,"4");
        int index3=getIndex(list,"6");
        int index4=getIndex(list,"7");

        System.out.println(index1);
        System.out.println(index2);
        System.out.println(index3);
        System.out.println(index4);



    }
    public static int getIndex(ArrayList<Student> list,String id) {//获取索引，为防止有多个学号做准备
        for (int i = 0; i < list.size(); i++) {
            Student stu=list.get(i);
            String sid=stu.getSid(); //
            if (id.equals(sid)){//判断在集合中是否存在跟传入的id一样的id
                return i;
            }
        }
        return -1;
    }
}
